home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / snk.c < prev    next >
C/C++ Source or Header  |  2000-03-20  |  20KB  |  716 lines

  1. #include "driver.h"
  2. #include "vidhrdw/generic.h"
  3.  
  4. int snk_bg_tilemap_baseaddr, gwar_sprite_placement;
  5.  
  6. #define MAX_VRAM_SIZE (64*64*2)
  7.  
  8. //static int k = 0; /*for debugging use */
  9.  
  10. static int shadows_visible = 0; /* toggles rapidly to fake translucency in ikari warriors */
  11.  
  12. static void print( struct osd_bitmap *bitmap, int num, int row ){
  13.     char *digit = "0123456789abcdef";
  14.  
  15.     drawgfx( bitmap,Machine->uifont,
  16.         digit[(num>>4)&0xf],
  17.         0,
  18.         0,0, /* no flip */
  19.         24,row*8+8,
  20.         0,TRANSPARENCY_NONE,0);
  21.     drawgfx( bitmap,Machine->uifont,
  22.         digit[num&0xf],
  23.         0,
  24.         0,0, /* no flip */
  25.         32,row*8+8,
  26.         0,TRANSPARENCY_NONE,0);
  27. }
  28.  
  29. #define GFX_CHARS            0
  30. #define GFX_TILES            1
  31. #define GFX_SPRITES            2
  32. #define GFX_BIGSPRITES            3
  33.  
  34. void snk_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom){
  35.     int i;
  36.     int num_colors = 1024;
  37.     for( i=0; i<num_colors; i++ ){
  38.         int bit0,bit1,bit2,bit3;
  39.  
  40.         colortable[i] = i;
  41.  
  42.         bit0 = (color_prom[0] >> 0) & 0x01;
  43.         bit1 = (color_prom[0] >> 1) & 0x01;
  44.         bit2 = (color_prom[0] >> 2) & 0x01;
  45.         bit3 = (color_prom[0] >> 3) & 0x01;
  46.         *palette++ = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  47.  
  48.         bit0 = (color_prom[num_colors] >> 0) & 0x01;
  49.         bit1 = (color_prom[num_colors] >> 1) & 0x01;
  50.         bit2 = (color_prom[num_colors] >> 2) & 0x01;
  51.         bit3 = (color_prom[num_colors] >> 3) & 0x01;
  52.         *palette++ = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  53.  
  54.         bit0 = (color_prom[2*num_colors] >> 0) & 0x01;
  55.         bit1 = (color_prom[2*num_colors] >> 1) & 0x01;
  56.         bit2 = (color_prom[2*num_colors] >> 2) & 0x01;
  57.         bit3 = (color_prom[2*num_colors] >> 3) & 0x01;
  58.         *palette++ = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  59.  
  60.         color_prom++;
  61.     }
  62. }
  63.  
  64. void ikari_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom){
  65.     int i;
  66.     snk_vh_convert_color_prom( palette, colortable, color_prom);
  67.  
  68.     palette += 6*3;
  69.     /*
  70.         pen#6 is used for translucent shadows;
  71.         we'll just make it dark grey for now
  72.     */
  73.     for( i=0; i<256; i+=8 ){
  74.         palette[i*3+0] = palette[i*3+1] = palette[i*3+2] = 14;
  75.     }
  76. }
  77.  
  78. int snk_vh_start( void ){
  79.     dirtybuffer = malloc( MAX_VRAM_SIZE );
  80.     if( dirtybuffer ){
  81.         tmpbitmap = osd_new_bitmap( 512, 512, Machine->scrbitmap->depth );
  82.         if( tmpbitmap ){
  83.             memset( dirtybuffer, 0xff, MAX_VRAM_SIZE  );
  84.             shadows_visible = 1;
  85.             return 0;
  86.         }
  87.         free( dirtybuffer );
  88.     }
  89.     return 1;
  90. }
  91.  
  92. void snk_vh_stop( void ){
  93.     osd_free_bitmap( tmpbitmap );
  94.     tmpbitmap = 0;
  95.     free( dirtybuffer );
  96.     dirtybuffer = 0;
  97. }
  98.  
  99. /**************************************************************************************/
  100.  
  101. static void tnk3_draw_background( struct osd_bitmap *bitmap, int scrollx, int scrolly ){
  102.     const struct rectangle *clip = &Machine->drv->visible_area;
  103.     const struct GfxElement *gfx = Machine->gfx[GFX_TILES];
  104.     int offs;
  105.     for( offs=0; offs<64*64*2; offs+=2 ){
  106.         int tile_number = videoram[offs];
  107.         unsigned char attributes = videoram[offs+1];
  108.  
  109.         if( tile_number!=dirtybuffer[offs] || attributes != dirtybuffer[offs+1] ){
  110.             int sy = ((offs/2)%64)*8;
  111.             int sx = ((offs/2)/64)*8;
  112.             int color = (attributes&0xf)^0x8;
  113.  
  114.             dirtybuffer[offs] = tile_number;
  115.             dirtybuffer[offs+1] = attributes;
  116.  
  117.             tile_number += 256*((attributes>>4)&0x3);
  118.  
  119.             drawgfx( tmpbitmap,gfx,
  120.                 tile_number,
  121.                 color,
  122.                 0,0, /* no flip */
  123.                 sx,sy,
  124.                 0,TRANSPARENCY_NONE,0);
  125.         }
  126.     }
  127.     {
  128.         copyscrollbitmap(bitmap,tmpbitmap,
  129.             1,&scrollx,1,&scrolly,
  130.             clip,
  131.             TRANSPARENCY_NONE,0);
  132.     }
  133. }
  134.  
  135. void tnk3_draw_text( struct osd_bitmap *bitmap, int bank, unsigned char *source ){
  136.     const struct GfxElement *gfx = Machine->gfx[GFX_CHARS];
  137.     int offs;
  138.  
  139.     bank*=256;
  140.  
  141.     for( offs = 0;offs <0x400; offs++ ){
  142.         drawgfx( bitmap, gfx,
  143.             source[offs]+bank,
  144.             source[offs]>>5,
  145.             0,0, /* no flip */
  146.             16+(offs/32)*8,(offs%32)*8+8,
  147.             0,
  148.             TRANSPARENCY_PEN,15 );
  149.     }
  150. }
  151.  
  152. void tnk3_draw_status( struct osd_bitmap *bitmap, int bank, unsigned char *source ){
  153.     const struct rectangle *clip = &Machine->drv->visible_area;
  154.     const struct GfxElement *gfx = Machine->gfx[GFX_CHARS];
  155.     int offs;
  156.  
  157.     bank *= 256;
  158.  
  159.     for( offs = 0; offs<64; offs++ ){
  160.         int tile_number = source[offs+30*32];
  161.         int sy = (offs % 32)*8+8;
  162.         int sx = (offs / 32)*8;
  163.  
  164.         drawgfx(bitmap,gfx,
  165.             tile_number+bank,
  166.             tile_number>>5,
  167.             0,0, /* no flip */
  168.             sx,sy,
  169.             clip,TRANSPARENCY_NONE,0);
  170.  
  171.         tile_number = source[offs];
  172.         sx += 34*8;
  173.  
  174.         drawgfx(bitmap,gfx,
  175.             tile_number+bank,
  176.             tile_number>>5,
  177.             0,0, /* no flip */
  178.             sx,sy,
  179.             clip,TRANSPARENCY_NONE,0);
  180.     }
  181. }
  182.  
  183. void tnk3_draw_sprites( struct osd_bitmap *bitmap, int xscroll, int yscroll ){
  184.     static int n = 50;
  185.     const unsigned char *source = spriteram;
  186.     const unsigned char *finish = source+n*4;
  187.     struct rectangle clip = Machine->drv->visible_area;
  188. /*
  189. if( keyboard_pressed( KEYCODE_J ) ){
  190.     while( keyboard_pressed( KEYCODE_J ) ){}
  191.     n--;
  192. }
  193. if( keyboard_pressed( KEYCODE_K ) ){
  194.     while( keyboard_pressed( KEYCODE_K ) ){}
  195.     n++;
  196. }
  197. */
  198.  
  199.     while( source<finish ){
  200.         int attributes = source[3]; /* YBBX.CCCC */
  201.         int tile_number = source[1];
  202.         int sy = source[0] + ((attributes&0x10)?256:0) - yscroll;
  203.         int sx = source[2] + ((attributes&0x80)?256:0) - xscroll;
  204.         int color = attributes&0xf;
  205.  
  206.         if( attributes&0x40 ) tile_number += 256;
  207.         if( attributes&0x20 ) tile_number += 512;
  208.  
  209.         drawgfx(bitmap,Machine->gfx[GFX_SPRITES],
  210.             tile_number,
  211.             color,
  212.             0,0,
  213.             (256-sx)&0x1ff,sy&0x1ff,
  214.             &clip,TRANSPARENCY_PEN,7);
  215.  
  216.         source+=4;
  217.     }
  218. }
  219.  
  220. void tnk3_vh_screenrefresh( struct osd_bitmap *bitmap, int full_refresh ){
  221.     unsigned char *ram = memory_region(REGION_CPU1);
  222.     int attributes = ram[0xc800];
  223.     /*
  224.         X-------
  225.         -X------    character bank (for text layer)
  226.         --X-----
  227.         ---X----    scrolly MSB (background)
  228.         ----X---    scrolly MSB (sprites)
  229.         -----X--
  230.         ------X-    scrollx MSB (background)
  231.         -------X    scrollx MSB (sprites)
  232.     */
  233.  
  234.     /* to be moved to memmap */
  235.     spriteram = &ram[0xd000];
  236.     videoram = &ram[0xd800];
  237.  
  238.     {
  239.         int scrolly =  -8+ram[0xcb00]+((attributes&0x10)?256:0);
  240.         int scrollx = -16+ram[0xcc00]+((attributes&0x02)?256:0);
  241.         tnk3_draw_background( bitmap, -scrollx, -scrolly );
  242.     }
  243.  
  244.     {
  245.         int scrolly =  8+ram[0xc900] + ((attributes&0x08)?256:0);
  246.         int scrollx = 30+ram[0xca00] + ((attributes&0x01)?256:0);
  247.         tnk3_draw_sprites( bitmap, scrollx, scrolly );
  248.     }
  249.  
  250.     {
  251.         int bank = (attributes&0x40)?1:0;
  252.         tnk3_draw_text( bitmap, bank, &ram[0xf800] );
  253.         tnk3_draw_status( bitmap, bank, &ram[0xfc00] );
  254.     }
  255. }
  256.  
  257. /**************************************************************************************/
  258.  
  259. static void ikari_draw_background( struct osd_bitmap *bitmap, int xscroll, int yscroll ){
  260.     const struct GfxElement *gfx = Machine->gfx[GFX_TILES];
  261.     const unsigned char *source = &memory_region(REGION_CPU1)[snk_bg_tilemap_baseaddr];
  262.  
  263.     int offs;
  264.     for( offs=0; offs<32*32*2; offs+=2 ){
  265.         int tile_number = source[offs];
  266.         unsigned char attributes = source[offs+1];
  267.  
  268.         if( tile_number!=dirtybuffer[offs] ||
  269.             attributes != dirtybuffer[offs+1] ){
  270.  
  271.             int sy = ((offs/2)%32)*16;
  272.             int sx = ((offs/2)/32)*16;
  273.  
  274.             dirtybuffer[offs] = tile_number;
  275.             dirtybuffer[offs+1] = attributes;
  276.  
  277.             tile_number+=256*(attributes&0x3);
  278.  
  279.             drawgfx(tmpbitmap,gfx,
  280.                 tile_number,
  281.                 (attributes>>4), /* color */
  282.                 0,0, /* no flip */
  283.                 sx,sy,
  284.                 0,TRANSPARENCY_NONE,0);
  285.         }
  286.     }
  287.  
  288.     {
  289.         struct rectangle clip = Machine->drv->visible_area;
  290.         clip.min_x += 16;
  291.         clip.max_x -= 16;
  292.         copyscrollbitmap(bitmap,tmpbitmap,
  293.             1,&xscroll,1,&yscroll,
  294.             &clip,
  295.             TRANSPARENCY_NONE,0);
  296.     }
  297. }
  298.  
  299. static void ikari_draw_text( struct osd_bitmap *bitmap ){
  300.     const struct rectangle *clip = &Machine->drv->visible_area;
  301.     const struct GfxElement *gfx = Machine->gfx[GFX_CHARS];
  302.     const unsigned char *source = &memory_region(REGION_CPU1)[0xf800];
  303.  
  304.     int offs;
  305.     for( offs = 0;offs <0x400; offs++ ){
  306.         int tile_number = source[offs];
  307.         int sy = (offs % 32)*8+8;
  308.         int sx = (offs / 32)*8+16;
  309.  
  310.         drawgfx(bitmap,gfx,
  311.             tile_number,
  312.             8, /* color - vreg needs mapped! */
  313.             0,0, /* no flip */
  314.             sx,sy,
  315.             clip,TRANSPARENCY_PEN,15);
  316.     }
  317. }
  318.  
  319. static void ikari_draw_status( struct osd_bitmap *bitmap ){
  320.     /*    this is drawn above and below the main display */
  321.  
  322.     const struct rectangle *clip = &Machine->drv->visible_area;
  323.     const struct GfxElement *gfx = Machine->gfx[GFX_CHARS];
  324.     const unsigned char *source = &memory_region(REGION_CPU1)[0xfc00];
  325.  
  326.     int offs;
  327.     for( offs = 0; offs<64; offs++ ){
  328.         int tile_number = source[offs+30*32];
  329.         int sy = 20+(offs % 32)*8 - 16;
  330.         int sx = (offs / 32)*8;
  331.  
  332.         drawgfx(bitmap,gfx,
  333.             tile_number,
  334.             8, /* color */
  335.             0,0, /* no flip */
  336.             sx,sy,
  337.             clip,TRANSPARENCY_NONE,0);
  338.  
  339.         tile_number = source[offs];
  340.         sx += 34*8;
  341.  
  342.         drawgfx(bitmap,gfx,
  343.             tile_number,
  344.             8, /* color */
  345.             0,0, /* no flip */
  346.             sx,sy,
  347.             clip,TRANSPARENCY_NONE,0);
  348.     }
  349. }
  350.  
  351. static void ikari_draw_sprites_16x16( struct osd_bitmap *bitmap, int start, int quantity, int xscroll, int yscroll )
  352. {
  353.     int transp_mode  = shadows_visible ? TRANSPARENCY_PEN : TRANSPARENCY_PENS;
  354.     int transp_param = shadows_visible ? 7 : ((1<<7) | (1<<6));
  355.  
  356.     int which;
  357.     const unsigned char *source = &memory_region(REGION_CPU1)[0xe800];
  358.  
  359.     struct rectangle clip = Machine->drv->visible_area;
  360.     clip.min_x += 16;
  361.     clip.max_x -= 16;
  362.  
  363.     for( which = start*4; which < (start+quantity)*4; which+=4 )
  364.     {
  365.         int attributes = source[which+3]; /* YBBX.CCCC */
  366.         int tile_number = source[which+1] + ((attributes&0x60)<<3);
  367.         int sy = - yscroll + source[which]  +((attributes&0x10)?256:0);
  368.         int sx =   xscroll - source[which+2]+((attributes&0x80)?0:256);
  369.  
  370.         drawgfx(bitmap,Machine->gfx[GFX_SPRITES],
  371.             tile_number,
  372.             attributes&0xf, /* color */
  373.             0,0, /* flip */
  374.             -16+(sx & 0x1ff), -16+(sy & 0x1ff),
  375.             &clip,transp_mode,transp_param);
  376.     }
  377. }
  378.  
  379. static void ikari_draw_sprites_32x32( struct osd_bitmap *bitmap, int start, int quantity, int xscroll, int yscroll )
  380. {
  381.     int transp_mode  = shadows_visible ? TRANSPARENCY_PEN : TRANSPARENCY_PENS;
  382.     int transp_param = shadows_visible ? 7 : ((1<<7) | (1<<6));
  383.  
  384.     int which;
  385.     const unsigned char *source = &memory_region(REGION_CPU1)[0xe000];
  386.  
  387.     struct rectangle clip = Machine->drv->visible_area;
  388.     clip.min_x += 16;
  389.     clip.max_x -= 16;
  390.  
  391.     for( which = start*4; which < (start+quantity)*4; which+=4 )
  392.     {
  393.         int attributes = source[which+3];
  394.         int tile_number = source[which+1];
  395.         int sy = - yscroll + source[which] + ((attributes&0x10)?256:0);
  396.         int sx = xscroll - source[which+2] + ((attributes&0x80)?0:256);
  397.         if( attributes&0x40 ) tile_number += 256;
  398.  
  399.         drawgfx( bitmap,Machine->gfx[GFX_BIGSPRITES],
  400.             tile_number,
  401.             attributes&0xf, /* color */
  402.             0,0, /* flip */
  403.             -16+(sx & 0x1ff), -16+(sy & 0x1ff),
  404.             &clip,transp_mode,transp_param );
  405.  
  406.     }
  407. }
  408.  
  409. void ikari_vh_screenrefresh( struct osd_bitmap *bitmap, int full_refresh){
  410.     const unsigned char *ram = memory_region(REGION_CPU1);
  411.  
  412.     shadows_visible = !shadows_visible;
  413.  
  414.     {
  415.         int attributes = ram[0xc900];
  416.         int scrolly =  8-ram[0xc800] - ((attributes&0x01) ? 256:0);
  417.         int scrollx = 13-ram[0xc880] - ((attributes&0x02) ? 256:0);
  418.         ikari_draw_background( bitmap, scrollx, scrolly );
  419.     }
  420.     {
  421.         int attributes = ram[0xcd00];
  422.  
  423.         int sp16_scrolly = -7 + ram[0xca00] + ((attributes&0x04) ? 256:0);
  424.         int sp16_scrollx = 44 + ram[0xca80] + ((attributes&0x10) ? 256:0);
  425.  
  426.         int sp32_scrolly =  9 + ram[0xcb00] + ((attributes&0x08) ? 256:0);
  427.         int sp32_scrollx = 28 + ram[0xcb80] + ((attributes&0x20) ? 256:0);
  428.  
  429.         ikari_draw_sprites_16x16( bitmap,  0, 25, sp16_scrollx, sp16_scrolly );
  430.         ikari_draw_sprites_32x32( bitmap,  0, 25, sp32_scrollx, sp32_scrolly );
  431.         ikari_draw_sprites_16x16( bitmap, 25, 25, sp16_scrollx, sp16_scrolly );
  432.     }
  433.     ikari_draw_text( bitmap );
  434.     ikari_draw_status( bitmap );
  435. }
  436.  
  437. /**************************************************************/
  438.  
  439. static void tdfever_draw_background( struct osd_bitmap *bitmap,
  440.         int xscroll, int yscroll )
  441. {
  442.     const struct GfxElement *gfx = Machine->gfx[GFX_TILES];
  443.     const unsigned char *source = &memory_region(REGION_CPU1)[0xd000]; //d000
  444.  
  445.     int offs;
  446.     for( offs=0; offs<32*32*2; offs+=2 ){
  447.         int tile_number = source[offs];
  448.         unsigned char attributes = source[offs+1];
  449.  
  450.         if( tile_number!=dirtybuffer[offs] ||
  451.             attributes != dirtybuffer[offs+1] ){
  452.  
  453.             int sy = ((offs/2)%32)*16;
  454.             int sx = ((offs/2)/32)*16;
  455.  
  456.             int color = (attributes>>4); /* color */
  457.  
  458.             dirtybuffer[offs] = tile_number;
  459.             dirtybuffer[offs+1] = attributes;
  460.  
  461.             tile_number+=256*(attributes&0xf);
  462.  
  463.             drawgfx(tmpbitmap,gfx,
  464.                 tile_number,
  465.                 color,
  466.                 0,0, /* no flip */
  467.                 sx,sy,
  468.                 0,TRANSPARENCY_NONE,0);
  469.         }
  470.     }
  471.  
  472.     {
  473.         struct rectangle clip = Machine->drv->visible_area;
  474.         copyscrollbitmap(bitmap,tmpbitmap,
  475.             1,&xscroll,1,&yscroll,
  476.             &clip,
  477.             TRANSPARENCY_NONE,0);
  478.     }
  479. }
  480.  
  481. static void tdfever_draw_sprites( struct osd_bitmap *bitmap, int xscroll, int yscroll ){
  482.     int transp_mode  = shadows_visible ? TRANSPARENCY_PEN : TRANSPARENCY_PENS;
  483.     int transp_param = shadows_visible ? 15 : ((1<<15) | (1<<14));
  484.  
  485.     const struct GfxElement *gfx = Machine->gfx[GFX_SPRITES];
  486.     const unsigned char *source = &memory_region(REGION_CPU1)[0xe000];
  487.  
  488.     int which;
  489.  
  490.     struct rectangle clip = Machine->drv->visible_area;
  491.  
  492.     for( which = 0; which < 32*4; which+=4 ){
  493.         int attributes = source[which+3];
  494.         int tile_number = source[which+1] + 8*(attributes&0x60);
  495.  
  496.         int sy = - yscroll + source[which];
  497.         int sx = xscroll - source[which+2];
  498.         if( attributes&0x10 ) sy += 256;
  499.         if( attributes&0x80 ) sx -= 256;
  500.  
  501.         sx &= 0x1ff; if( sx>512-32 ) sx-=512;
  502.         sy &= 0x1ff; if( sy>512-32 ) sy-=512;
  503.  
  504.         drawgfx(bitmap,gfx,
  505.             tile_number,
  506.             (attributes&0xf), /* color */
  507.             0,0, /* no flip */
  508.             sx,sy,
  509.             &clip,transp_mode,transp_param);
  510.     }
  511. }
  512.  
  513. static void tdfever_draw_text( struct osd_bitmap *bitmap, int attributes, int dx, int dy, int base ){
  514.     int bank = attributes>>4;
  515.     int color = attributes&0xf;
  516.  
  517.     const struct rectangle *clip = &Machine->drv->visible_area;
  518.     const struct GfxElement *gfx = Machine->gfx[GFX_CHARS];
  519.  
  520.     const unsigned char *source = &memory_region(REGION_CPU1)[base];
  521.  
  522.     int offs;
  523.  
  524.     int bank_offset = bank*256;
  525.  
  526.     for( offs = 0;offs <0x800; offs++ ){
  527.         int tile_number = source[offs];
  528.         int sy = dx+(offs % 32)*8;
  529.         int sx = dy+(offs / 32)*8;
  530.  
  531.         if( source[offs] != 0x20 ){
  532.             drawgfx(bitmap,gfx,
  533.                 tile_number + bank_offset,
  534.                 color,
  535.                 0,0, /* no flip */
  536.                 sx,sy,
  537.                 clip,TRANSPARENCY_PEN,15);
  538.         }
  539.     }
  540. }
  541.  
  542. void tdfever_vh_screenrefresh( struct osd_bitmap *bitmap, int fullrefresh ){
  543.     const unsigned char *ram = memory_region(REGION_CPU1);
  544.     shadows_visible = !shadows_visible;
  545.  
  546.     {
  547.         unsigned char bg_attributes = ram[0xc880];
  548.         int bg_scroll_y = -30 - ram[0xc800] - ((bg_attributes&0x01)?256:0);
  549.         int bg_scroll_x = 141 - ram[0xc840] - ((bg_attributes&0x02)?256:0);
  550.         tdfever_draw_background( bitmap, bg_scroll_x, bg_scroll_y );
  551.     }
  552.  
  553.     {
  554.         unsigned char sprite_attributes = ram[0xc900];
  555.         int sprite_scroll_y =   65 + ram[0xc980] + ((sprite_attributes&0x80)?256:0);
  556.         int sprite_scroll_x = -135 + ram[0xc9c0] + ((sprite_attributes&0x40)?256:0);
  557.         tdfever_draw_sprites( bitmap, sprite_scroll_x, sprite_scroll_y );
  558.     }
  559.  
  560.     {
  561.         unsigned char text_attributes = ram[0xc8c0];
  562.         tdfever_draw_text( bitmap, text_attributes, 0,0, 0xf800 );
  563.     }
  564. }
  565.  
  566. void ftsoccer_vh_screenrefresh( struct osd_bitmap *bitmap, int fullrefresh ){
  567.     const unsigned char *ram = memory_region(REGION_CPU1);
  568.     shadows_visible = !shadows_visible;
  569.     {
  570.         unsigned char bg_attributes = ram[0xc880];
  571.         int bg_scroll_y = - ram[0xc800] - ((bg_attributes&0x01)?256:0);
  572.         int bg_scroll_x = 16 - ram[0xc840] - ((bg_attributes&0x02)?256:0);
  573.         tdfever_draw_background( bitmap, bg_scroll_x, bg_scroll_y );
  574.     }
  575.  
  576.     {
  577.         unsigned char sprite_attributes = ram[0xc900];
  578.         int sprite_scroll_y =  31 + ram[0xc980] + ((sprite_attributes&0x80)?256:0);
  579.         int sprite_scroll_x = -40 + ram[0xc9c0] + ((sprite_attributes&0x40)?256:0);
  580.         tdfever_draw_sprites( bitmap, sprite_scroll_x, sprite_scroll_y );
  581.     }
  582.  
  583.     {
  584.         unsigned char text_attributes = ram[0xc8c0];
  585.         tdfever_draw_text( bitmap, text_attributes, 0,0, 0xf800 );
  586.     }
  587. }
  588.  
  589. static void gwar_draw_sprites_16x16( struct osd_bitmap *bitmap, int xscroll, int yscroll ){
  590.     const struct GfxElement *gfx = Machine->gfx[GFX_SPRITES];
  591.     const unsigned char *source = &memory_region(REGION_CPU1)[0xe800];
  592.  
  593.     const struct rectangle *clip = &Machine->drv->visible_area;
  594.  
  595.     int which;
  596.     for( which=0; which<(64)*4; which+=4 )
  597.     {
  598.         int attributes = source[which+3]; /* YBBX.BCCC */
  599.         int tile_number = source[which+1];
  600.         int sy = -xscroll + source[which];
  601.         int sx =  yscroll - source[which+2];
  602.         if( attributes&0x10 ) sy += 256;
  603.         if( attributes&0x80 ) sx -= 256;
  604.  
  605.         if( attributes&0x08 ) tile_number += 256;
  606.         if( attributes&0x20 ) tile_number += 512;
  607.         if( attributes&0x40 ) tile_number += 1024;
  608.  
  609.         sy &= 0x1ff; if( sy>512-16 ) sy-=512;
  610.         sx = (-sx)&0x1ff; if( sx>512-16 ) sx-=512;
  611.  
  612.         drawgfx(bitmap,gfx,
  613.             tile_number,
  614.             (attributes&7), /* color */
  615.             0,0, /* flip */
  616.             sx,sy,
  617.             clip,TRANSPARENCY_PEN,15 );
  618.     }
  619. }
  620.  
  621. void gwar_draw_sprites_32x32( struct osd_bitmap *bitmap, int xscroll, int yscroll ){
  622.     const struct GfxElement *gfx = Machine->gfx[GFX_BIGSPRITES];
  623.     const unsigned char *source = &memory_region(REGION_CPU1)[0xe000];
  624.  
  625.     const struct rectangle *clip = &Machine->drv->visible_area;
  626.  
  627.     int which;
  628.     for( which=0; which<(32)*4; which+=4 )
  629.     {
  630.         int attributes = source[which+3];
  631.         int tile_number = source[which+1] + 8*(attributes&0x60);
  632.  
  633.         int sy = - xscroll + source[which];
  634.         int sx = yscroll - source[which+2];
  635.         if( attributes&0x10 ) sy += 256;
  636.         if( attributes&0x80 ) sx -= 256;
  637.  
  638.         sy = (sy&0x1ff);
  639.         sx = ((-sx)&0x1ff);
  640.         if( sy>512-32 ) sy-=512;
  641.         if( sx>512-32 ) sx-=512;
  642.  
  643.         drawgfx(bitmap,gfx,
  644.             tile_number,
  645.             (attributes&0xf), /* color */
  646.             0,0, /* no flip */
  647.             sx,sy,
  648.             clip,TRANSPARENCY_PEN,15);
  649.     }
  650. }
  651.  
  652. void gwar_vh_screenrefresh( struct osd_bitmap *bitmap, int full_refresh ){
  653.     const unsigned char *ram = memory_region(REGION_CPU1);
  654.     unsigned char bg_attributes, sp_attributes;
  655.  
  656.     {
  657.         int bg_scroll_y, bg_scroll_x;
  658.  
  659.         if( gwar_sprite_placement==2 ) { /* Gwar alternate */
  660.             bg_attributes = ram[0xf880];
  661.             sp_attributes = ram[0xfa80];
  662.             bg_scroll_y = - ram[0xf800] - ((bg_attributes&0x01)?256:0);
  663.             bg_scroll_x  = 16 - ram[0xf840] - ((bg_attributes&0x02)?256:0);
  664.         } else {
  665.             bg_attributes = ram[0xc880];
  666.             sp_attributes = ram[0xcac0];
  667.             bg_scroll_y = - ram[0xc800] - ((bg_attributes&0x01)?256:0);
  668.             bg_scroll_x  = 16 - ram[0xc840] - ((bg_attributes&0x02)?256:0);
  669.         }
  670.         tdfever_draw_background( bitmap, bg_scroll_x, bg_scroll_y );
  671.     }
  672.  
  673.     {
  674.         int sp16_y = ram[0xc900]+15;
  675.         int sp16_x = ram[0xc940]+8;
  676.         int sp32_y = ram[0xc980]+31;
  677.         int sp32_x = ram[0xc9c0]+8;
  678.  
  679.         if( gwar_sprite_placement ) /* gwar */
  680.         {
  681.             if( bg_attributes&0x10 ) sp16_y += 256;
  682.             if( bg_attributes&0x40 ) sp16_x += 256;
  683.             if( bg_attributes&0x20 ) sp32_y += 256;
  684.             if( bg_attributes&0x80 ) sp32_x += 256;
  685.         }
  686.         else{ /* psychos, bermudet, chopper1... */
  687.             unsigned char spp_attributes = ram[0xca80];
  688.             if( spp_attributes&0x04 ) sp16_y += 256;
  689.             if( spp_attributes&0x08 ) sp32_y += 256;
  690.             if( spp_attributes&0x10 ) sp16_x += 256;
  691.             if( spp_attributes&0x20 ) sp32_x += 256;
  692.         }
  693.         if (sp_attributes & 0x20)
  694.         {
  695.             gwar_draw_sprites_16x16( bitmap, sp16_y, sp16_x );
  696.             gwar_draw_sprites_32x32( bitmap, sp32_y, sp32_x );
  697.         }
  698.         else {
  699.             gwar_draw_sprites_32x32( bitmap, sp32_y, sp32_x );
  700.             gwar_draw_sprites_16x16( bitmap, sp16_y, sp16_x );
  701.         }
  702.     }
  703.  
  704.     {
  705.         if( gwar_sprite_placement==2) { /* Gwar alternate */
  706.             unsigned char text_attributes = ram[0xf8c0];
  707.             tdfever_draw_text( bitmap, text_attributes,0,0, 0xc800 );
  708.         }
  709.         else {
  710.             unsigned char text_attributes = ram[0xc8c0];
  711.             tdfever_draw_text( bitmap, text_attributes,0,0, 0xf800 );
  712.         }
  713.     }
  714. }
  715.  
  716.